package top.sirgo.jasper.demo;

import net.sf.jasperreports.engine.*;
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

public class JasperTable2 {

    public static void main(String[] args) throws JRException {
        String basePath = "D:\\workspace\\jasperdemo\\";

        String xmlFile = basePath + "src/main/resources/table.xml";
        JasperReport jreport = JasperCompileManager.compileReport(xmlFile);

        ArrayList<Order> orders = new ArrayList<Order>();

        orders.add(new Order("Item 1", new BigDecimal("5.4"), 4));
        orders.add(new Order("Item 2", new BigDecimal("2.3"), 3));
        orders.add(new Order("Item 3", new BigDecimal("1.5"), 8));
        orders.add(new Order("Item 4", new BigDecimal("4.0"), 2));

        JRBeanCollectionDataSource ds = new JRBeanCollectionDataSource(orders);

        Map params = new HashMap();
        params.put("datasource", ds);

        JasperPrint jprint = JasperFillManager.fillReport(jreport,
                params, new JREmptyDataSource());

        JasperExportManager.exportReportToPdfFile(jprint, basePath + "src/main/resources/order.pdf");
    }
}